
var cityname = '';
var tourlist = [];

var currentPage = 1;	//当前页数
var limit = 10;		//每页个数
var count = 0;	//总数

apiready = function() {
    
   	cityname = api.pageParam.name;
   	
   	$api.text($api.byId('title'), cityname + '线路');
   	
   	//上拉
	api.addEventListener({
		name: 'scrolltobottom'
	}, function (ret, err) {
       
		if(limit < count){
			limit += 10;
			getList();
	               
		}else{
			api.toast({
				msg: '下面没有啦...',
				duration: 1000,
				location: 'bottom'
			});
		}
	});
   	
   	//加载数据
   	getList();
}


function getList(){
	api.showProgress({
		title: '加载中...',
		modal: false
	});
	
	var url = '/app/tour/route?city='+cityname+'&page='+currentPage+'&limit='+limit;

	
	$api.get(serviceUrl+url,function(ret){
	
	    tourlist = ret.data;
	    count = ret.count;
	    
		showList(tourlist);
	  
	},'json');
}


function showList(list){

	var aHtml = "";
	
	if(list.length > 0){
		
		for(var i = 0; i < list.length; i++){
			
			aHtml += '<div class="am-u-sm-12" style="margin-top:3px;border-bottom:1px solid #F7E1B5;padding-top:10px;" onclick="enterDetail('+i+')">';
				aHtml += '<div class="am-u-sm-3" style="padding:0px;">';
					aHtml += '<img src="'+ serviceUrl+list[i].proDefImg +'" style="height:80px;">';
				aHtml += '</div>';
		
				aHtml += '<div class="am-u-sm-9" style="padding:0px;">';
					aHtml += '<div class="am-u-sm-12">'+ list[i].name +'</div>';
			
					aHtml += '<div class="am-u-sm-12 am-text-truncate" style="color:white;font-size:14px;margin-top:9px;">';
					aHtml += '</div>';
			
					aHtml += '<div class="am-u-sm-12" style="text-align: right">';
						aHtml += '<span style="color:#ff3300;font-weight:bold">';
							aHtml += '￥'+list[i].price;
						aHtml += '</span>';
						aHtml += '<font style="color:#9a9a9a;">起/人</font>';
					aHtml += '</div>';
				aHtml += '</div>';
    		aHtml += '</div>';
		}
		
	}else{
	
		aHtml += '<div class="am-u-sm-12" style="text-align:center;padding:5px 10px;">';
			aHtml += '<label>暂无线路信息...</label>';
		aHtml += '</div>';
	}
	
	$api.html($api.byId('tourlist'), aHtml);

	api.hideProgress();
}


function enterDetail(index){
	var tour = tourlist[index];
	
	openWin('tour_info', {'tour':tour});
}
